package wyp.library.ui.view;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.RelativeLayout;

public abstract class WypGroupView extends RelativeLayout implements OnClickListener, OnTouchListener {

	public interface WypGroupViewDelegate {
		public void onClick_WypGroupView(WypGroupView _view);
	}

	private WypGroupViewDelegate mDelegate;

	public WypGroupView(Context context) {
		super(context);
	}

	public WypGroupView(Context context, WypGroupViewDelegate _delegate) {
		super(context);
		this.setDelegate(_delegate);
	}

	public void setDelegate(WypGroupViewDelegate _delegate) {
		this.mDelegate = _delegate;
		this.setOnClickListener(this);
	}

	public WypGroupViewDelegate getDelegate() {
		this.setOnClickListener(this);
		return this.mDelegate;
	}

	@Override
	public void onClick(View v) {
		if (this.mDelegate != null) {
			this.mDelegate.onClick_WypGroupView(this);
		}
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		boolean _return = false;

		if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
			this.setHighlight();
		} else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
			this.setNormal();
		} else {
			_return = true;
		}
		return _return;
	}

	public void setOnClick(View _v) {
		_v.setOnClickListener(this);
	}

	public void setOnTouch(View _v) {
		_v.setOnTouchListener(this);
	}

	public abstract void setHighlight(Object... _objects);

	public abstract void setNormal(Object... _objects);
}
